# This example draws three rectangles in three different colors.
# A color is an object representing a combination of Red, Green, and Blue (RGB) intensity values. Valid RGB values are
# in the range 0 to 255. We can define a color in various ways. The most common are RGB decimal values or hexadecimal
# values. We can also use an RGBA value, which stands for Red, Green, Blue, Alpha. Here we add some extra information,
# regarding transparency. Alpha value of 255 defines full opacity, 0 is for full transparency, e.g. color is invisible.

import sys, random
from PySide import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()

    # Drawing is done within a paintEvent
    def paintEvent(self, event):
        # QtGui.QPainter class is responsible for all the low level painting. All the painting event go between begin()
        # and the end() methods. The actual painting in this program is delegated to the 'drawText' method
        painter = QtGui.QPainter()
        painter.begin(self)
        self.drawRectangles(event, painter)
        painter.end()

        self.setGeometry(200, 200, 350, 150)
        self.setWindowTitle("Drawing-Color Filled Rectangles")

    def drawRectangles(self, event, painter):
        color = QtGui.QColor(0, 0, 0)
        color.setNamedColor('#d4d4d4') # Here we define a color using a hexadecimal notation.
        painter.setPen(color)   # The above defined color is used for pen, which is used to draw outlines of shapes.

        #Here we define a brush and draw a rectangle. A brush is an elementary graphics object, which is used to draw
        # the background of a shape. The drawRect() method accepts four parameters. The first two are x, y values on
        # the axis. The third and fourth parameters are width and height of the rectangle. The method draws a rectangle
        # using current pen and current brush.
        painter.setBrush(QtGui.QColor(200, 0, 0))
        painter.drawRect(10, 15, 90, 60)

        painter.setBrush(QtGui.QColor(255, 80, 0, 160))
        painter.drawRect(130, 15, 90, 60)

        painter.setBrush(QtGui.QColor(25, 0, 90, 200))
        painter.drawRect(250, 15, 90, 60)



if __name__ == "__main__":
    appObject = QtGui.QApplication(sys.argv)
    ex = Window()
    ex.show()
    sys.exit(appObject.exec_())

